package com.gress.shop.dao.impl;

import com.gress.shop.bo.Action;
import com.gress.shop.bo.example.ActionExample;
import com.gress.shop.dao.IActionDao;
import com.gress.shop.mapper.ActionMapper;
import com.gress.shop.util.UUIDUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created xiongwen with 2018/3/6 15:44
 * Description:
 */
@Service
public class ActionDaoImpl implements IActionDao {

    @Resource
    private ActionMapper actionMapper;

    @Override
    public int deleteByExample(ActionExample example) {
        return actionMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(String id) {
        return actionMapper.deleteByPrimaryKey(id);
    }


    @Override
    public List<Action> selectByExample(ActionExample example) {
        return actionMapper.selectByExample(example);
    }

    @Override
    public Action selectByPrimaryKey(String id) {
        return actionMapper.selectByPrimaryKey(id);
    }

    @Override
    public Action insertOrUpdate(Action record) {
        if (StringUtils.isEmpty(record.getId())) {
            record.setId(UUIDUtil.getUUID());
            actionMapper.insertSelective(record);
        }else {
            actionMapper.updateByPrimaryKeySelective(record);
        }
        return record;
    }

    @Override
    public boolean checkIsExist(String id) {
        return null != selectByPrimaryKey(id);
    }

}
